package com.button.controller;

import com.button.domain.entity.User;
import com.button.domain.request.UserRequestVo;
import com.button.domain.vo.PageResult;
import com.button.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping(value = "/list")
    @ApiOperation(value = "获取用户列表", httpMethod = "POST", response = List.class,notes = "button")
    public PageResult listPage(@RequestBody UserRequestVo userRequestVo) {
        Page<Object> startPage = PageHelper.startPage(userRequestVo.getPage(), userRequestVo.getPageline());
        List<User> list = userService.getListPage(userRequestVo);
        return PageResult.getPage(userRequestVo.getPage(),startPage.getPageSize(), startPage.getTotal(), list);
    }
}
